<?php

class FileAction extends CommonAction{
    public function flash_upload(){
        $path = WEB_PATH.'attachment/'.date('Ym').'/';
        $filename = md5(uniqid(rand())).'.png';
        $web_path = '/attachment/'.date('Ym').'/'.$filename;
        $info = webuploader('name',$path,$web_path,$filename);
        exit($info['info']);
    }
	public function do_upload()
	{
		if(intval($_REQUEST['upload_type'])==0)
		$result = $this->uploadFile();
		else
		$result = $this->uploadImage();
		if($result['status'] == 1)
		{
			$list = $result['data'];
			if(intval($_REQUEST['upload_type'])==0)
			$file_url = $list[0]['recpath'].$list[0]['savename'];
			else
			$file_url = $list[0]['bigrecpath'].$list[0]['savename'];
            header('Content-type: text/html; charset=UTF-8');
            echo json_encode(array('error' => 0, 'url' => $file_url),JSON_HEX_TAG);
            exit();
		}
		else
		{
            $this->alert($result['info']);
		}
	}
	public function do_upload_img()
	{
		if(intval($_REQUEST['upload_type'])==0) {
			$result = $this->uploadFile();
		}
		else{
			$result = $this->uploadImage();
		}
		if($result['status'] == 1)
		{
			$list = $result['data'];
			if(intval($_REQUEST['upload_type'])==0){
				$file_url = $list[0]['recpath'].$list[0]['savename'];
			}
			else{
				$file_url = $list[0]['bigrecpath'].$list[0]['savename'];
			}
            header('Content-type: text/html; charset=UTF-8');
            echo json_encode(array('error' => 0, 'url' => $file_url),JSON_HEX_TAG);
            exit();
		}
		else
		{
            $this->alert($result['info']);
		}
	}

    function alert($msg) {
        header('Content-type: text/html; charset=UTF-8');
        echo json_encode(array('error' => 1, 'message' => $msg),JSON_HEX_TAG);
        exit;
    }

	
	public function deleteImg()
	{
		B('FilterString');
		$ajax = intval($_REQUEST['ajax']);
		$file = $_REQUEST['file'];
		$file = explode("..",$file);
		$file = $file[4];
		$file = substr($file,1);
		@unlink(get_real_path().$file);
		save_log(l("DELETE_SUCCESS"),1);
		$this->success(l("DELETE_SUCCESS"),$ajax);
	}
}
?>